package String;

public class 重复的子字符串 {
    public boolean repeatedSubstringPattern(String s) {
        int[] next = new int[s.length()];
        for (int i = 0, j = 1; j < s.length(); j++) {
            while (i > 0 && s.charAt(i) != s.charAt(j)) i = next[i - 1];
            if (s.charAt(i) == s.charAt(j)) i++;
            next[j] = i;
        }
        int lastIndex = next[s.length() - 1];
        return lastIndex > 0 && lastIndex % (s.length() - lastIndex) == 0;
    }
}
